import java.util.ArrayList;

public class Test3 {
    public static void main(String[] args) {
        String strSql = "delete from table where :aa :bb :cc :dd ";
        String[] parameterNames = getParamFromString(strSql, ":", " ");
        strSql = replaceParamString(strSql, parameterNames, "? ", ":", " ");
        System.out.println();
    }

    public static String replaceParamString(String source, String[] l, String aCode, String aStartStr, String aEndStr) {
        for(int i = 0; i < l.length; ++i) {
            source = replaceParamString(source, aStartStr + l[i] + aEndStr, aCode);
        }

        return source;
    }

    public static String replaceParamString(String source, String s1, String s2) {
        int index = source.indexOf(s1);
        if (index == 0) {
            return s2 + source.substring(s1.length());
        } else {
            return index > 0 ? source.substring(0, index) + s2 + source.substring(index + s1.length()) : source;
        }
    }

    public static String[] getParamFromString(String aSourceString, String aStartStr, String aEndStr) {
        aSourceString = aSourceString + aEndStr;
        String strSource = aSourceString;
        ArrayList strKey = new ArrayList();
        int iStartIndex = aSourceString.indexOf(aStartStr);
        int iStartLength = aStartStr.length();
        int iEndLength = aEndStr.length();
        String strTemp = "";
        strTemp = aSourceString.substring(iStartIndex + iStartLength, aSourceString.length());
        int iEndIndex = strTemp.indexOf(aEndStr) + aSourceString.substring(0, iStartIndex + iStartLength).length();
        if (iEndIndex == iStartIndex) {
            strKey.add(strTemp);
        }

        while(iStartIndex != -1 && iEndIndex != -1 && iStartIndex < iEndIndex) {
            strTemp = strSource.substring(iStartIndex + iStartLength, iEndIndex);
            strKey.add(strTemp);
            strSource = strSource.substring(iEndIndex + iEndLength, strSource.length());
            iStartIndex = strSource.indexOf(aStartStr);
            strTemp = strSource.substring(iStartIndex + iStartLength, strSource.length());
            iEndIndex = strTemp.indexOf(aEndStr) + strSource.substring(0, iStartIndex + iStartLength).length();
        }

        return (String[])strKey.toArray(new String[0]);
    }
}
